﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Dillon.CSV
{
    class LexerReader : TextReader
    {
        List<int> buffer;
        TextReader reader;

        public LexerReader(TextReader reader)
        {
            this.buffer = new List<int>();
            this.reader = reader;
        }

        public override int Peek()
        {
            return Peek(0);
        }

        public override int Read()
        {
            int c = Peek();
            buffer.RemoveAt(0);
            return c;
        }

        public int Peek(int step)
        {
            while (step >= buffer.Count)
            {
                buffer.Add(reader.Read());
            }

            if (step < 0)
                return -1;

            return buffer[step];
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
                reader.Dispose();
            base.Dispose(disposing);
        }
    }
}
